#include "widget.h"
#include "ui_widget.h"
#include<QIcon>
#include<QDebug>
#include<QKeySequence>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //创建图标
    QIcon icon(":/cat.png");
    ui->pushButton->setText("");
    ui->pushButton->resize(150,150);
    ui->pushButton->setIcon(icon);
    QSize size=ui->pushButton->iconSize();
    qDebug()<<size;
    ui->pushButton->setIconSize(QSize(50,50));
    ui->pushButton_up->setIcon(QIcon(":/up.png"));
    ui->pushButton_down->setIcon(QIcon(":/down.png"));
    ui->pushButton_left->setIcon(QIcon(":/left.png"));
    ui->pushButton_right->setIcon(QIcon(":/right.png"));

    //鼠标自动重复触发
    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);
    //重复触发的延时时间
    ui->pushButton_up->setAutoRepeatDelay(1000);
    ui->pushButton_down->setAutoRepeatDelay(3000);
    ui->pushButton_left->setAutoRepeatDelay(4000);
    ui->pushButton_right->setAutoRepeatDelay(2000);

    //重复触发的时间
    ui->pushButton_up->setAutoRepeatInterval(500);
    ui->pushButton_down->setAutoRepeatInterval(5000);
    ui->pushButton_left->setAutoRepeatInterval(5000);
    ui->pushButton_right->setAutoRepeatInterval(5000);


    //设置快捷键
//    ui->pushButton_up->setShortcut(QKeySequence("w"));
//    ui->pushButton_down->setShortcut(QKeySequence("s"));
//    ui->pushButton_left->setShortcut(QKeySequence("a"));
//    ui->pushButton_right->setShortcut(QKeySequence("d"));
    ui->pushButton_up->setShortcut(QKeySequence(Qt::Key_W));
    ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));
    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{

    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_down_clicked()
{

    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());
}
